package org.smarthings.http;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;

public class HttpServerImpl implements org.smarthings.Server {
	private Server server;

	public void start(String host, int port) {
		try {
			server = new Server(port);
			WebAppContext handler = new WebAppContext();
			handler.setResourceBase("/");
			handler.setContextPath("/");
			handler.addServlet(new ServletHolder(new HttpServletImpl()), "/*");
			server.setHandler(handler);
			server.start();
			System.out.println(HttpFactory.PROTOCOL + " SERVER STARTED");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void stop() {
		try {
			server.stop();
			System.out.println(HttpFactory.PROTOCOL + " SERVER STOPPED");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getProtocol() {
		return HttpFactory.PROTOCOL;
	}

	public void update(String uri) {
		// do nothing
	}
}
